package com.sky.controller.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags="购物车相关接口")
public class ShoppingCartController {
	@Autowired
	private ShoppingCartService shoppingCartservice;
	/*
	 * 添加购物车
	 * @param shoppingCartDTO
	 * @return
	 */
	@PostMapping("/add")
	@ApiOperation("添加购物车")
	public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO)
	{
		log.info("添加购物车，商品信息为：{}",shoppingCartDTO);
		 shoppingCartservice.addShoppingCart(shoppingCartDTO);
		return Result.success();
	}
	/**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list(){
        return Result.success(shoppingCartservice.showShoppingCart());
    }
    /**
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result Clean()
    {
    	log.info("清空购物车");
    	shoppingCartservice.cleanshopping();
    	return Result.success();
    }
    @PostMapping("/sub")
    @ApiOperation("减少数量")
    public Result SubAmount(@RequestBody ShoppingCartDTO shoppingCartDTO )
    {
    	log.info("减少购物车的物品数量");
    	//调用service进行操作
    	shoppingCartservice.sub(shoppingCartDTO);
    	return Result.success();
    }
  
}
